<?

//Initiate Authenticate
SecurityRedirect ();

//initiate Vars 
define("PRIMARY_KEY","nobkt");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_cashbankreceived.php";
$FileTemplate  = "ais_transaction_cashbankreceived_list.html";
$TableName     = "ais_memorial";
$SubHeaderTitle= "Transaction Cash/Bank - Received";
$PageSize      = 10 ;
$HTMLGridList  = "CashBankGrid";
//************ FORM ACTION **************
	if (GetParam("Action","")=="Delete") {
		DeleteRecord ("txtCheck",$PageSize);
	}

//Initiate Database Table For Search;
$FCode = GetParam("transNoSearch","");
$RCode = GetParam("transNoRef","");
$TRDate = GetParam("transDate","");
$QueryGet  = GetQueryString("All", array('PageNum'));


//******* DATABASE FORM QUERY ***********
$SQL = "SELECT * FROM `$TableName` ";
$SQLCount = "SELECT count(*) FROM `$TableName` ";
$WHERE   = " (nobkt like 'TK%' OR nobkt like 'TB%')";
$WHERE  .= " AND urut like '999' AND ".QueryLedger();

//Retrieve Parameter from search

if ($FCode) {
	$CustomWhere = " nobkt like '".$FCode."%'";
	if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
	else $WHERE = $CustomWhere;	
}

if ($RCode) {
	$CustomWhere = " noref like '".$RCode."%'";
	if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
	else $WHERE = $CustomWhere;	
}

if ($TRDate) {
	$TransDate = explode("/",$TRDate);
	$CustomWhere = " tglbkt = '$TransDate[2]-$TransDate[1]-$TransDate[0]'";
	if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
	else $WHERE = $CustomWhere;	
}


if (strlen($WHERE)) {
	$SQL = $SQL."WHERE ".$WHERE;
	$SQLCount .= "WHERE ".$WHERE;
}
else $SQL = $SQL;
$SQL .= " ORDER BY memorial_id DESC ";
//$SQL .= " ORDER BY tglbkt DESC, nobkt DESC";


//Select Customer 
//$SQLDept = "SELECT * FROM tbldept";

//******* SHOW FORM CONTENT *********
$PageNum = 1;
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ; 

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
//print $SQL;
$TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ; 
$TBS->Show();


function DeleteRecord ($sequence_name,$PageSize) {
	global $DBConnection,$FileName,$TableName;	
	for ($x=1;$x<=$PageSize;$x++) {				
		if (GetParam($sequence_name.$x,""))	{
			$DBConnection->Delete("$TableName",$sequence_name.$x);
	    }
	}
	header("Location: $FileName");
	exit;	
	
}

?>
